import { getAnswerList, getSingleSurveyStatistic, getCycleSurveyStatistic, getAvg, getAssessmentSurveyStatistic, getFieldData } from '@/services/answer';
import { filterObj } from '@/utils';
export default {
  name: 'answer',
  namespaced: true,
  state: {
    answerListSource: null,
    singleSurveyStatisticSource: null,
    cycleSurveyStatisticSource: null,
    avgSource: null,
    assessmentSurveyStatisticSource: null,
    fieldDataSource: null
  },
  mutations: {
    setAnswerList(state, val) {
      state.answerListSource = val;
    },
    setSingleSurveyStatistic(state, val) {
      state.singleSurveyStatisticSource = val;
    },
    setCycleSurveyStatistic(state, val) {
      state.cycleSurveyStatisticSource = val;
    },
    setAvg(state, val) {
      state.avgSource = val;
    },
    setAssessmentSurveyStatistic(state, val) {
      state.assessmentSurveyStatisticSource = val;
    },
    setFieldData(state, val) {
      state.fieldDataSource = val;
    }
  },
  actions: {
    async getAnswerList({ commit }, params) {
      await getAnswerList(filterObj(params)).then(res => {
        commit('setAnswerList', res.data || null)
      }).catch(() => {
        commit('setAnswerList', null)
      })
    },
    async getSingleSurveyStatistic({ commit }, params) {
      await getSingleSurveyStatistic(filterObj(params)).then(res => {
        commit('setSingleSurveyStatistic', res.data || null)
      }).catch(() => {
        commit('setSingleSurveyStatistic', null)
      })
    },
    async getCycleSurveyStatistic({ commit }, params) {
      await getCycleSurveyStatistic(filterObj(params)).then(res => {
        commit('setCycleSurveyStatistic', res.data || null)
      }).catch(() => {
        commit('setCycleSurveyStatistic', null)
      })
    },
    async getAvg({ commit }, params) {
      await getAvg(filterObj(params)).then(res => {
        commit('setAvg', res.data || null)
      }).catch(() => {
        commit('setAvg', null)
      })
    },
    async getAssessmentSurveyStatistic({ commit }, params) {
      await getAssessmentSurveyStatistic(filterObj(params)).then(res => {
        commit('setAssessmentSurveyStatistic', res.data || null)
      }).catch(() => {
        commit('setAssessmentSurveyStatistic', null)
      })
    },
    async getFieldData({ commit }, params) {
      await getFieldData(params).then(res => {
        commit('setFieldData', res.data || null)
      }).catch(() => {
        commit('setFieldData', null)
      })
    }
  }
}